import moment from 'moment';

const today = moment(new Date(), 'YYYY/MM/DD').format('YYYY/MM/DD');
const pushStatus = [{ value: '0', name: '未推送' }, { value: '1', name: '推送成功' }, { value: '2', name: '推送失败' }];
const serviceType = [{ value: '0', name: '社保' }, { value: '1', name: '公积金' }];
function getTypeByValue(value, sourcesData) {
    for (let i = 0; i < sourcesData.length; i++) {
        if (sourcesData[i].value == value) {
            return sourcesData[i].name;
        }
    }
}
const getSearchInputConfig = (cityList) => {
    return [
        {
            type: 'select',
            placeholder: '请选择城市名称',
            name: 'cityCode',
            label: '城市名称',
            optionData: cityList,
            nameFiled: 'cityName',
            valueFiled: 'cityCode',
            selectProps: {
                allowClear: true,
                showSearch: true
            }
        },
        {
            type: 'select',
            placeholder: '请选择推送状态',
            name: 'pushStatus',
            label: '推送状态',
            optionData: pushStatus,
            selectProps: {
                allowClear: true,
            }
        },
        {
            type: 'select',
            placeholder: '请选择服务类型',
            name: 'type',
            label: '服务类型',
            optionData: serviceType,
            selectProps: {
                allowClear: true,
            }
        }
    ]
};
const getEditConfig = (activeRecord, cityList) => {
    const dateFormat = 'YYYY-MM';
    return [
        {
            type: 'input',
            name: 'id',
            decorator: true,
            initialValue: activeRecord.id || '',
            isHide: true
        },
        {
            type: 'select',
            name: 'payCity',
            label: '城市',
            decorator: true,
            initialValue: String(activeRecord.payCity || ''),
            optionList: {
                name: 'cityName',
                value: 'cityCode',
                list: cityList
            },
            selectProps: {
                allowClear: true,
                optionFilterProp: 'children',
                showSearch: true
            },
            decoratorConfig: {
                rules: [{ required: true, message: '城市不能为空' }],
            },
        },
        {
            type: 'select',
            placeholder: '请选择服务类型',
            name: 'serviceType',
            decorator: true,
            initialValue: activeRecord.serviceType > -1 ? String(activeRecord.serviceType) : '',
            optionList: {
                list: serviceType
            },
            label: '服务类型',
        },
        {
            type: 'monthPicker',
            name: 'time',
            label: '最新缴费月份',
            format: 'YYYY-MM',
            decorator: true,
            grid: { sm: 24, md: 12, xl: 8, xxl: 8 },
            initialValue: moment(activeRecord.maintenanceTime || today, dateFormat),
            decoratorConfig: {
                rules: [{ required: true, message: '维护时间不能为空' }],
            },
        }
    ];
}
const getTableConfig = (OptionNode) => {
    return [
        {
            title: '序号',
            dataIndex: 'id',
            width: '6%',
            render: (text, record, index) => (index + 1)
        },
        {
            title: '城市编号',
            dataIndex: 'cityCode',
            width: '10%'
        },
        {
            title: '城市名称',
            dataIndex: 'cityName',
            width: '10%'
        },
        {
            title: '城市操作',
            width: '12%',
            render: (text, record, index) => (<OptionNode id={text} index={index} record={record} text='城市参数'></OptionNode>),
        },
        {
            title: '业务操作',
            render: text => { return configData['buzz_type'] && configData['buzz_type'][text] },
            width: '12%',
            render: (text, record, index) => (<OptionNode id={text} index={index} record={record} text='业务参数'></OptionNode>),
        },
        {
            title: '基数/比例操作',
            render: text => { return authUtil.formatDate(text, 'Y-M-D h:m:s') },
            width: '14%',
            render: (text, record, index) => (<OptionNode id={text} index={index} record={record} text='基数/比例参数'></OptionNode>),
        },
        {
            title: '城市抓取配置',
            render: text => { return configData['auth_source'] && configData['auth_source'][text] },
            width: '12%',
            render: (text, record, index) => (<OptionNode id={text} index={index} record={record} text='城市抓取配置'></OptionNode>),
        }
    ];
}
/**
 * 
* @description 推送抽屉内表单配置信息
 * @param {*} activeRecord 当前数据
 * @param {*} type       推送类型（单条or多条）
 * @param {*} addonAfter 特殊的按钮
 * @param {*} appIdConfig 应用分类
 */
const pushDrawerConfig = (activeRecord, type, addonAfter, appIdConfig) => {
    const dateFormat = 'YYYY/MM/DD';
    const base = [
        {
            type: 'input',
            name: 'documentId',
            decorator: true,
            initialValue: activeRecord.id || '',
            isHide: true
        },
        {
            type: 'input',
            name: 'serviceType',
            decorator: true,
            initialValue: activeRecord.serviceType || '',
            isHide: true
        },
        {
            type: 'input',
            name: 'cityCode',
            decorator: true,
            initialValue: activeRecord.payCity || '',
            isHide: true
        },
        {
            type: 'input',
            name: 'cityName',
            decorator: true,
            initialValue: activeRecord.cityName || '',
            isHide: true
        },
        {
            type: 'radio',
            name: 'appid',
            label: '应用名称',
            decorator: true,
            required: true,
            optionList: {
                list: appIdConfig
            },
        },
        {
            type: 'select',
            name: 'serviceType',
            decorator: true,
            initialValue: '1',
            required: true,
            optionList: {
                list: [{ name: 'app', value: '1' }]
            },
            label: '服务类型',
        }
    ];
    const one = [
        {
            type: 'input',
            name: 'userId',
            label: '用户ID',
            decorator: true,
            required: true,
            decoratorConfig: {
                rules: [{ required: true, message: '用户ID不能为空' }],
            },
        }
    ]
    const multiple = [
        {
            type: 'select',
            name: 'phoneType',
            label: '手机类型',
            decorator: true,
            initialValue: '0',
            optionList: {
                list: [{ name: 'Android', value: '0' }, { name: 'IOS', value: '1' }]
            },
        },
        {
            type: 'combinationinput',
            name: 'noticeNumver',
            label: '预计APP人数',
            optionList: {
                list: [{ name: 'before', value: null }, { name: 'after', value: addonAfter }]
            }
        },
        {
            type: 'input',
            name: 'inBoxMsgCount',
            label: '预计站内信人数'
        },
        {
            type: 'input',
            name: 'tagsName',
            label: '',
            initialValue: activeRecord.cityName + getTypeByValue(activeRecord.serviceType, serviceType),
            isHide: true
        }
    ];
    const lastData = [
        {
            type: 'input',
            name: 'noticeTitle',
            label: '通知标题',
            decorator: true,
            required: true,
            decoratorConfig: {
                rules: [{ required: true, message: '通知标题不能为空' }],
            },
        },
        {
            type: 'textarea',
            name: 'noticeContent',
            label: '通知摘要',
            decorator: true,
            required: true,
            decoratorConfig: {
                rules: [{ required: true, message: '通知摘要不能为空' }],
            },
        },
        {
            type: 'input',
            name: 'noticePassword',
            label: '密码',
            placeholder: '请输入密码',
            decorator: true,
            required: true,
            decoratorConfig: {
                rules: [{ required: true, message: '密码不能为空' }],
            },
        }
    ]
    let result;
    // 多用户
    if (type == '0') {
        result = base.concat(multiple)
    } else {
        result = base.concat(one)
    }
    return result.concat(lastData);
};
export default {
    getSearchInputConfig,
    getEditConfig,
    getTableConfig,
    pushDrawerConfig
}